package com.app.mvc.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Restrictions;
import org.hibernate.mapping.Join;

import com.app.mvc.dao.AbstractHibernateDaoSupport;
import com.app.mvc.dao.CategoryDao;
import com.app.mvc.model.Category;
import com.app.mvc.model.Location;
import com.app.mvc.ultil.HibernateUtil;

public class CategoryDaoImpl extends
		AbstractHibernateDaoSupport<Category, Long> implements CategoryDao {

	public CategoryDaoImpl() {
		super(Category.class);
		// TODO Auto-generated constructor stub
	}

	@Override
	public List<Category> getAll() {
		// TODO Auto-generated method stub
		return findAll();
	}

	@Override
	public List<Category> getCategoryByLocation(long ID) {
		// TODO Auto-generated method stub
		Criteria criteria = HibernateUtil.getSession()
				.createCriteria(Category.class)
				.setFetchMode("location", FetchMode.JOIN)
				.add(Restrictions.eq("location.id", ID));
		return criteria.list();
	}

}
